package com.simulated.communication.networkprocessing;

import io.netty.channel.Channel;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Markburt
 * @Description : user和channel的关系类,用于存储对应的关联
 * @DATE: 2020/5/4
 * @TIME: 上午 10:05
 * @YEAR: 2020
 * @Version :
 **/
public class UserChannelRelation {

    /***
     * 定义静态变量
     */
    public static HashMap<String, Channel> manager = new HashMap<>();

    /**
     * 定义存储方法
     * @param senderId
     * @param channel
     */
    public static void put(String senderId, Channel channel){
        manager.put(senderId,channel);
    }

    /**
     * 定义获取方法
     * @param senderId
     * @return
     */
    public static Channel get(String senderId){
        //根据senderId获取对应的channel
        return manager.get(senderId);
    }

    /***
     * 输出所有的user和channel信息
     */
    public static void output(){
        for (Map.Entry<String, Channel> channelEntry : manager.entrySet()) {
            System.out.println("user: "+ channelEntry.getKey()+", channelId: "+channelEntry.getValue().id().asLongText());
        }
    }
}
